/*
*global function
*/
// var Think = {
//             "APP": '__APP__',
//             "URL": '__URL__',
//             "ROOT": '__ROOT__',
//             "PUBLIC": '__PUBLIC__'
//         };

function logout() {
    $.ajax({
        url: Think.APP+"/Public/logout",
        type: 'post',
        dataType: 'json',
        success: function (data) {
            history.go(0)
        },
        error: function (xhr) {
            alert("注销失败");
        }

    })
}


//远程验证
function GetRemoteInfo(postUrl, data) {
    debugger;
    var remote = {
        type: "POST",
        async: true,
        url: postUrl,
        dataType: "json",
        data: data,
        dataFilter: function(result) {
            debugger;
            var obj = $.parseJSON(result);
            if(obj.state=="success" || obj.state == 1){
                return true;
            }
            return false;
        }
    };
    return remote;
}

/**
	 * 将form里面的内容序列化成json
	 * 相同的checkbox用分号拼接起来
	 * @param {dom} 指定的选择器
	 * @method serializeJson
	 * */
	$.fn.serializeJson=function(formObj){
	  var serializeObj={};
	  var array=formObj.find('input');
	  $(array).each(function(){
	  	if(!this.value){
	    		return false;
	    	}
	    if(serializeObj[this.name]){
	      serializeObj[this.name]+=';'+this.value;
	    }else{
	      serializeObj[this.name]=this.value;
	    }
	  });
	  return serializeObj;
	};




	var wh = $(window).height();
	var h = wh-150;
	$(".main").css("min-height",h);


	var jsArray = {};
//加载指定的js脚本，成功后返回回调
function LoadScript(scriptName, callback) {
    if (!jsArray[scriptName]) {
        jsArray[scriptName] = true;

        $.getScript(scriptName, callback);
    }
    else if (callback) {
        callback();
    }
}



/**
 * ajax同步加载html文件代码块
 * @param  {[string]} container [要填充的div容器]
 * @param  {[string]} url)(     [加载html文件地址]
 */
function loadHtmlData(container,url){
    $(container).empty();
    container = $(container);

    $.ajax({
        type: "GET",
        //url: url,
        url: url + "?time=" + new Date(),
        dataType: 'html',
        cache: false, // (warning: this will cause a timestamp and will call the request twice)
        beforeSend: function() {
            debugger;
            container.html('<h3><i class="fa fa-cog fa-spin"></i> 正在加载，请稍后...</h3>');
            toggleLoadingFlash();
            if (container[0] == $("#content")[0]) {

                $("html").animate({
                    scrollTop: 0
                }, "fast");
            }
        },
        success: function(data) {

            container.css({
                opacity: '0.0'
            }).html(data).delay(100).animate({
                opacity: '1.0'
            }, 1000);
            setTimeout(function(){
                 toggleLoadingFlash();
             },1500)

        },
        error: function(xhr, ajaxOptions, thrownError) {
            container.html('<h4 style="margin-top:10px; display:block; text-align:left"><i class="fa fa-warning txt-color-orangeDark"></i> 出错啦 404！ 没有发现指定的页面。</h4>');
        },
        async: false
    });
}


function toggleLoadingFlash(){
    var loadingDivObj = $("#loadingLayout");
    loadingDivObj.toggleClass('hide');
}